package de.cbf.cam.dsa.facet.weapon_ranged.helper;

import java.util.ArrayList;
import java.util.List;

import de.cbf.cam.dsa.facet.weapon_ranged.FacetWeaponRangedConstants;
import de.cbf.util.entity.facet.constants.ConstantsFontColorLogView;
import de.cbf.util.entity.facet.util.TextPartStyled;
import de.cbf.util.uuidheader.entities.UUIDHeader;
import de.cbf.util.uuidheader.exceptions.EntityMergeException;

public class WeaponRanged_CombatValues extends UUIDHeader implements FacetWeaponRangedConstants{
	
	protected String 		fTp;//TODO should be DiceThrowDescription
	protected Integer		fLoadingActions;
	protected Double		fRangeMin;
	protected Double		fRangeVeryShort;
	protected Double		fRangeShort;
	protected Double		fRangeMedium;
	protected Double		fRangeLong;
	protected Double 		fRangeExtremelyLong;
	protected Integer		fDamageVeryShort;
	protected Integer		fDamageShort;
	protected Integer		fDamageMedium;
	protected Integer		fDamageLong;
	protected Integer 		fDamageExtremelyLong;
	
	@Override
	protected void init() {
		super.init();		
		fTp					 = UNSET_TP;
		fLoadingActions		 = UNSET_LOADING_ACTIONS;
		fRangeMin			 = UNSET_RANGE_MIN;
		fRangeVeryShort		 = UNSET_RANGE_VERY_SHORT;
		fRangeShort			 = UNSET_RANGE_SHORT;
		fRangeMedium		 = UNSET_RANGE_MEDIUM;
		fRangeLong			 = UNSET_RANGE_LONG;
		fRangeExtremelyLong  = UNSET_RANGE_EXTREMELY_LONG;
		fDamageVeryShort	 = UNSET_DAMAGE_VERY_SHORT;
		fDamageShort		 = UNSET_DAMAGE_SHORT;
		fDamageMedium		 = UNSET_DAMAGE_MEDIUM;
		fDamageLong			 = UNSET_DAMAGE_LONG;
		fDamageExtremelyLong = UNSET_DAMAGE_EXTREMELY_LONG;
	}
	
	@Override
	protected void doMergeDataFrom(UUIDHeader entity, boolean i_am_older)
			throws EntityMergeException {		
		if (entity instanceof WeaponRanged_CombatValues) {
			WeaponRanged_CombatValues other = (WeaponRanged_CombatValues) entity;
			if(i_am_older){
				this.fTp					= other.fTp;
				this.fLoadingActions		= other.fLoadingActions;
				this.fRangeMin				= other.fRangeMin;
				this.fRangeVeryShort		= other.fRangeVeryShort;
				this.fRangeShort			= other.fRangeShort;
				this.fRangeMedium			= other.fRangeMedium;
				this.fRangeLong				= other.fRangeLong;
				this.fRangeExtremelyLong	= other.fRangeExtremelyLong;
				this.fDamageVeryShort		= other.fDamageVeryShort;
				this.fDamageShort			= other.fDamageShort;
				this.fDamageMedium			= other.fDamageMedium;
				this.fDamageLong			= other.fDamageLong;
				this.fDamageExtremelyLong	= other.fDamageExtremelyLong;
			}
		}else{
			String mergeEntityClass = entity == null? "null":entity.getClass().getName();
			String errorMsg ="EntityToMerge "+mergeEntityClass+" does not fit class:"+this.getClass().getName();
			throw new EntityMergeException(errorMsg);
		}
	}
	
	public List<TextPartStyled> getStyledDescription() {
		List<TextPartStyled> textStyleInfo = new ArrayList<TextPartStyled>();
		TextPartStyled textPart;
		//fTp
		textPart = new TextPartStyled();
		textPart.setText("\t"+TEXT_LOG_TP);
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_CATEGORY);		
		textStyleInfo.add(textPart);
		//fTp value
		textPart = new TextPartStyled();		
		textPart.setText(fTp+" \n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_VALUE);		
		textStyleInfo.add(textPart );

		//fLoadingActions
		textPart = new TextPartStyled();
		textPart.setText("\t"+TEXT_LOG_LOADING_ACTIONS);
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_CATEGORY);		
		textStyleInfo.add(textPart);
		//fLoadingActions value
		textPart = new TextPartStyled();		
		textPart.setText(fLoadingActions+" \n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_VALUE);		
		textStyleInfo.add(textPart );
		
		//fRangeMin
		textPart = new TextPartStyled();
		textPart.setText("\t"+TEXT_LOG_RANGE_MIN);
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_CATEGORY);		
		textStyleInfo.add(textPart);
		//fRangeMin value
		textPart = new TextPartStyled();		
		textPart.setText(fRangeMin+" \n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_VALUE);		
		textStyleInfo.add(textPart );
		
		//Ranges
		textPart = new TextPartStyled();
		textPart.setText("\t"+TEXT_LOG_RANGES+"\n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_CATEGORY);		
		textStyleInfo.add(textPart);
		//Ranges value
		textPart = new TextPartStyled();		
		textPart.setText("\t\t"+fRangeVeryShort+"/"+fRangeShort+"/"+fRangeMedium+"/"+fRangeLong+"/"+fRangeExtremelyLong+"\n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_VALUE);		
		textStyleInfo.add(textPart );
		
		//Damage
		textPart = new TextPartStyled();
		textPart.setText("\t"+TEXT_LOG_DAMAGES+"\n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_CATEGORY);		
		textStyleInfo.add(textPart);
		//Damage value
		textPart = new TextPartStyled();		
		textPart.setText("\t\t"+fDamageVeryShort+"/"+fDamageShort+"/"+fDamageMedium+"/"+fDamageLong+"/"+fDamageExtremelyLong+"\n");
		textPart.setStyleConstant(ConstantsFontColorLogView.STYLE_VALUE);		
		textStyleInfo.add(textPart );
				
		return textStyleInfo;
	}
	
	public String hasUnsetValues(){
		StringBuffer result = new StringBuffer();
		if(UNSET_TALENT != null && UNSET_TALENT.equals(fTp)){
			result.append(TEXT_UNSET_TALENT+"\n");
		}
		if(UNSET_TP.equals(fTp)){
			result.append(TEXT_UNSET_TP+"\n");
		}
		if(UNSET_LOADING_ACTIONS.equals(fLoadingActions)){
			result.append(TEXT_UNSET_LOADING_ACTIONS+"\n");
		}
		if(UNSET_RANGE_MIN.equals(fRangeMin)){
			result.append(TEXT_UNSET_RANGE_MIN+"\n");
		}
		if(UNSET_RANGE_VERY_SHORT.equals(fRangeVeryShort)){
			result.append(TEXT_UNSET_RANGE_VERY_SHORT+"\n");
		}
		if(UNSET_RANGE_SHORT.equals(fRangeShort)){
			result.append(TEXT_UNSET_RANGE_SHORT+"\n");
		}
		if(UNSET_RANGE_MEDIUM.equals(fRangeMedium)){
			result.append(TEXT_UNSET_RANGE_MEDIUM+"\n");
		}
		if(UNSET_RANGE_LONG.equals(fRangeLong)){
			result.append(TEXT_UNSET_RANGE_LONG+"\n");
		}
		if(UNSET_RANGE_EXTREMELY_LONG.equals(fRangeExtremelyLong)){
			result.append(TEXT_UNSET_RANGE_EXTREMELY_LONG+"\n");
		}
		if(UNSET_DAMAGE_VERY_SHORT.equals(fDamageVeryShort)){
			result.append(TEXT_UNSET_DAMAGE_VERY_SHORT+"\n");
		}
		if(UNSET_DAMAGE_SHORT.equals(fDamageShort)){
			result.append(TEXT_UNSET_DAMAGE_SHORT+"\n");
		}
		if(UNSET_DAMAGE_MEDIUM.equals(fDamageMedium)){
			result.append(TEXT_UNSET_DAMAGE_MEDIUM+"\n");
		}
		if(UNSET_DAMAGE_LONG.equals(fDamageLong)){
			result.append(TEXT_UNSET_DAMAGE_LONG+"\n");
		}	
		if(UNSET_DAMAGE_EXTREMELY_LONG.equals(fDamageExtremelyLong)){
			result.append(TEXT_UNSET_DAMAGE_EXTREMELY_LONG+"\n");
		}	
		return result.toString();		
	}
	
	
	public String getTp(){
		return fTp;
	}
	public void setTp(String newTp) {
		if(newTp == null || newTp.equals(fTp)) return;
		String oldTp = this.fTp;
		this.fTp = newTp;
		propertyChangeSupport.fireIndexedPropertyChange(PN_TP, PI_TP,
				oldTp,this.fTp);	
	}	

	public Integer getLoadingActions(){
		return fLoadingActions;
	}
	public void setLoadingActions(Integer newLoadingActions) {
		if(newLoadingActions == null || newLoadingActions.equals(fLoadingActions)) return;
		Integer oldLoadingActions = this.fLoadingActions;
		this.fLoadingActions = newLoadingActions;
		propertyChangeSupport.fireIndexedPropertyChange(PN_LOANDING_ACTIONS, PI_LOADING_ACTIONS,
				oldLoadingActions,this.fLoadingActions);	
	}	

	public Double getRangeMin(){
		return fRangeMin;
	}

	public void setRangeMin(Double newRangeMin) {
		if(newRangeMin == null || newRangeMin.equals(fRangeMin)) return;
		Double oldRangeMin = this.fRangeMin;
		this.fRangeMin = newRangeMin;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RangeMin, PI_RangeMin,
				oldRangeMin,this.fRangeMin);	
	}	
	
	public Double getRangeVeryShort(){
		return fRangeVeryShort;
	}
	public void setRangeVeryShort(Double newRangeVeryShort) {
		if(newRangeVeryShort == null || newRangeVeryShort.equals(fRangeVeryShort)) return;
		Double oldRangeVeryShort = this.fRangeVeryShort;
		this.fRangeVeryShort = newRangeVeryShort;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RANGE_VERY_SHORT, PI_RANGE_VERY_SHORT,
				oldRangeVeryShort,this.fRangeVeryShort);	
	}		
	
	public Double getRangeShort(){
		return fRangeShort;
	}
	public void setRangeShort(Double newRangeShort) {
		if(newRangeShort == null || newRangeShort.equals(fRangeShort)) return;
		Double oldRangeShort = this.fRangeShort;
		this.fRangeShort = newRangeShort;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RANGE_SHORT, PI_RANGE_SHORT,
				oldRangeShort,this.fRangeShort);	
	}	
	
	public Double getRangeMedium(){
		return fRangeMedium;
	}

	public void setRangeMedium(Double newRangeMedium) {
		if(newRangeMedium == null || newRangeMedium.equals(fRangeMedium)) return;
		Double oldRangeMedium = this.fRangeMedium;
		this.fRangeMedium = newRangeMedium;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RANGE_MEDIUM, PI_RANGE_MEDIUM,
				oldRangeMedium,this.fRangeMedium);	
	}
	
	public Double getRangeLong(){
		return fRangeLong;
	}

	public void setRangeLong(Double newRangeLong) {
		if(newRangeLong == null || newRangeLong.equals(fRangeLong)) return;
		Double oldRangeLong = this.fRangeLong;
		this.fRangeLong = newRangeLong;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RANGE_LONG, PI_RANGE_LONG,
				oldRangeLong,this.fRangeLong);	
	}	
	
	public Double getRangeExtremelyLong(){
		return fRangeExtremelyLong;
	}

	public void setRangeExtremelyLong(Double newRangeExtremelyLong) {
		if(newRangeExtremelyLong == null || newRangeExtremelyLong.equals(fRangeExtremelyLong)) return;
		Double oldRangeExtremelyLong = this.fRangeExtremelyLong;
		this.fRangeExtremelyLong = newRangeExtremelyLong;
		propertyChangeSupport.fireIndexedPropertyChange(PN_RANGE_EXTREMELY_LONG, PI_RANGE_EXTREMELY_LONG,
				oldRangeExtremelyLong,this.fRangeExtremelyLong);	
	}	
	
	public Integer getDamageVeryShort(){
		return fDamageVeryShort;
	}

	public void setDamageVeryShort(Integer newDamageVeryShort) {
		if(newDamageVeryShort == null || newDamageVeryShort.equals(fDamageVeryShort)) return;
		Integer oldDamageVeryShort = this.fDamageVeryShort;
		this.fDamageVeryShort = newDamageVeryShort;
		propertyChangeSupport.fireIndexedPropertyChange(PN_DAMAGE_VERY_SHORT, PI_DAMAGE_VERY_SHORT,
				oldDamageVeryShort,this.fDamageVeryShort);	
	}	
	
	public Integer getDamageShort(){
		return fDamageShort;
	}

	public void setDamageShort(Integer newDamageShort) {
		if(newDamageShort == null || newDamageShort.equals(fDamageShort)) return;
		Integer oldDamageShort = this.fDamageShort;
		this.fDamageShort = newDamageShort;
		propertyChangeSupport.fireIndexedPropertyChange(PN_DAMAGE_SHORT, PI_DAMAGE_SHORT,
				oldDamageShort,this.fDamageShort);	
	}	
	
	public Integer getDamageMedium(){
		return fDamageMedium;
	}

	public void setDamageMedium(Integer newDamageMedium) {
		if(newDamageMedium == null || newDamageMedium.equals(fDamageMedium)) return;
		Integer oldDamageMedium = this.fDamageMedium;
		this.fDamageMedium = newDamageMedium;
		propertyChangeSupport.fireIndexedPropertyChange(PN_DAMAGE_MEDIUM, PI_DAMAGE_MEDIUM,
				oldDamageMedium,this.fDamageMedium);	
	}	
	
	public Integer getDamageLong(){
		return fDamageLong;
	}
	public void setDamageLong(Integer newDamageLong) {
		if(newDamageLong == null || newDamageLong.equals(fDamageLong)) return;
		Integer oldDamageLong = this.fDamageLong;
		this.fDamageLong = newDamageLong;
		propertyChangeSupport.fireIndexedPropertyChange(PN_DAMAGE_LONG, PI_DAMAGE_LONG,
				oldDamageLong,this.fDamageLong);	
	}
	
	public Integer getDamageExtremelyLong(){
		return fDamageExtremelyLong;
	}

	public void setDamageExtremelyLong(Integer newDamageExtremelyLong) {
		if(newDamageExtremelyLong == null || newDamageExtremelyLong.equals(fDamageExtremelyLong)) return;
		Integer oldDamageExtremelyLong = this.fDamageExtremelyLong;
		this.fDamageExtremelyLong = newDamageExtremelyLong;
		propertyChangeSupport.fireIndexedPropertyChange(PN_DAMAGE_EXTREMELY_LONG, PI_DAMAGE_EXTREMELY_LONG,
				oldDamageExtremelyLong,this.fDamageExtremelyLong);	
	}

	

	
	
}
